﻿package data;

import java.util.Date;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class Task extends AbstractData {
	private transient long hotelId;
	private long id = -1; //Id form entity
	
	private String taskTitle;
	private String roomName;
	private Date due;
	private String status;
	private String detail;
	private boolean isStar;
	private boolean isTrash;
	private boolean isComplete;
	private boolean isSetDue;

	public static final String hotelIdField = "hotelId";
	public static final String taskTitleField = "taskTitle";
	public static final String roomNameField = "roomName";
	public static final String dueField = "due";
	public static final String statusField = "status";
	public static final String detailField = "detail";
	public static final String isStarField = "isStar";

	public Task()
	{
	}
	
	public Task(long id)
	{
		this.id = id;
	}
	
	@Override
	public long getId()	{
		return this.id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public long getHotelId() {
		return hotelId;
	}
	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}
	public String getTaskTitle() {
		return taskTitle;
	}
	public void setTaskTitle(String taskTitle) {
		this.taskTitle = taskTitle;
	}
	public String getRoomName() {
		return roomName;
	}
	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}
	public Date getDue() {
		return due;
	}
	public void setDue(Date due) {
		this.due = due;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getDetail() {
		return detail;
	}
	public void setDetail(String detail) {
		this.detail = detail;
	}
	public boolean isStar() {
		return isStar;
	}
	public void setStar(boolean isStar) {
		this.isStar = isStar;
	}

	public boolean isTrash() {
		return isTrash;
	}

	public void setTrash(boolean isTrash) {
		this.isTrash = isTrash;
	}

	public boolean isComplete() {
		return isComplete;
	}

	public void setComplete(boolean isComplete) {
		this.isComplete = isComplete;
	}

	public boolean isSetDue() {
		return isSetDue;
	}

	public void setSetDue(boolean isSetDue) {
		this.isSetDue = isSetDue;
	}
	
	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.Task);
		else
			item = new Entity(this.key);

		item.setProperty(hotelIdField, this.hotelId);
		item.setProperty(taskTitleField, this.taskTitle);
		item.setProperty(roomNameField, this.roomName);
		item.setProperty(dueField, this.due);
		item.setProperty(statusField, this.status);
		item.setProperty(detailField, this.detail);
		item.setProperty(isStarField, this.isStar);
		item.setProperty("isTrash", this.isTrash);
		item.setProperty("isComplete", this.isComplete);
		item.setProperty("isSetDue", this.isSetDue);
		return item;
	}
	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.taskTitle = (String) entity.getProperty("taskTitle");
		this.roomName = (String) entity.getProperty("roomName");
		this.due = (Date) entity.getProperty("due");
		this.status = (String) entity.getProperty("status");
		this.detail = (String) entity.getProperty("detail");
		this.isStar = (Boolean) entity.getProperty("isStar");
		this.isTrash = (entity.getProperty("isTrash")!=null)?(Boolean) entity.getProperty("isTrash"):null;
		this.isComplete = (entity.getProperty("isComplete")!=null)?(Boolean) entity.getProperty("isComplete"):null;
		this.isSetDue = (entity.getProperty("isSetDue")!=null)?(Boolean) entity.getProperty("isSetDue"):null;
		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.Task, this.id);
			setEntity(entity);
		}
	}
	
}
